dev.off()
remove()
rm(list = ls())
getwd()
setwd("./Data/")
library(meta)
library(metadat)
library(readxl)

library(forestplot)
data1 <- read_excel("./Data/bamboo_meta_rare_data.xlsx",sheet=1)
data2 <- read_excel("./Data/bamboo_meta_rare_data.xlsx",sheet=2)
data3 <- read_excel("./Data/bamboo_meta_rare_data.xlsx",sheet=3)



#-------------------subgroup-1---------------#
m1 <- metacont(n.e,mean.e,sd.e,
               n.c,mean.c,sd.c,
               data=data1,sm="SMD",
               byvar = Subgroup, 
               random=TRUE, 
               common = FALSE)
m1
forest(m1)

pdf('./p01.pdf', width = 9, height = 6)
p1<-forest(m1,studlab = paste(data$author,data$year,sep=","),
           family="sans",fontsize=9.5,
           lab.e=" 1-MCP ",lab.c=" Control ",
           lwd=1.5,
           col.diamond.fixed="lightslategray",
           col.diamond.lines.fixed="lightslategray",
           col.diamond.random="maroon",
           col.diamond.lines.random="maroon",
           col.square="skyblue",
           col.study="lightslategray",
           lty.fixed=2,digits.sd=2,
           plotwidth="8cm",
           colgap.forest.left="0.1cm",colgap.forest.right="0.1cm",
           just.forest="left",colgap.left="0.1cm",
           colgap.right="0.1cm")

print(p1)
dev.off()

#-------------------subgroup-2---------------#
m2 <- metacont(n.e,mean.e,sd.e,
               n.c,mean.c,sd.c,
               data=data2,sm="SMD",
               byvar = Subgroup, 
               random=TRUE, 
               common = FALSE)
m2
forest(m2)

pdf('./p02.pdf', width = 9, height = 5.5)
p2<-forest(m2,studlab = paste(data$author,data$year,sep=","),
           family="sans",fontsize=9.5,
           lab.e=" 1-MCP ",lab.c=" Control ",
           lwd=1.5,
           col.diamond.fixed="lightslategray",
           col.diamond.lines.fixed="lightslategray",
           col.diamond.random="maroon",
           col.diamond.lines.random="maroon",
           col.square="skyblue",
           col.study="lightslategray",
           lty.fixed=2,digits.sd=2,
           plotwidth="8cm",
           colgap.forest.left="0.1cm",colgap.forest.right="0.1cm",
           just.forest="left",colgap.left="0.1cm",
           colgap.right="0.1cm")

print(p2)
dev.off()

#-------------------subgroup-3---------------#
m3 <- metacont(n.e,mean.e,sd.e,
               n.c,mean.c,sd.c,
               data=data3,sm="SMD",
               byvar = Subgroup, 
               random=TRUE, 
               common = FALSE)
m3
forest(m3)

pdf('./p03.pdf', width = 9.5, height = 9.5)
p3<-forest(m3,studlab = paste(data$author,data$year,sep=","),
           family="sans",fontsize=9.5,
           lab.e=" 1-MCP ",lab.c=" Control ",
           lwd=1.5,
           col.diamond.fixed="lightslategray",
           col.diamond.lines.fixed="lightslategray",
           col.diamond.random="maroon",
           col.diamond.lines.random="maroon",
           col.square="skyblue",
           col.study="lightslategray",
           lty.fixed=2,digits.sd=2,
           plotwidth="8cm",
           colgap.forest.left="0.1cm",colgap.forest.right="0.1cm",
           just.forest="left",colgap.left="0.1cm",
           colgap.right="0.1cm")

print(p3)
dev.off()



library(ggplot2)


pdf('./p01-1.pdf', width = 9.5, height = 3.5)
p1_1<-forest(metainf(m1,pooled="random"),
       studlab = paste("Omitting:", data1$author,"(",data1$year,")","-" ,data1$Subgroup),
       family="sans",fontsize=9.5,
       lab.e="1-MCP",
       lab.c="Control",
       lwd=2,
       col.diamond.fixed="lightslategray",
       col.diamond.lines.fixed="lightslategray",
       col.diamond.random="maroon",
       col.diamond.lines.random="maroon",
       col.square="blue",
       col.study="lightslategray",
       lty.fixed=2,plotwidth="5cm")
print(p1_1)
dev.off()


pdf('./p02-1.pdf', width = 9.5, height = 3.5)
p2_1<-forest(metainf(m2,pooled="random"),
             studlab = paste("Omitting:", data2$author,"(",data2$year,")","-" ,data2$Subgroup),
             family="sans",fontsize=9.5,
             lab.e="1-MCP",
             lab.c="Control",
             lwd=2,
             col.diamond.fixed="lightslategray",
             col.diamond.lines.fixed="lightslategray",
             col.diamond.random="maroon",
             col.diamond.lines.random="maroon",
             col.square="blue",
             col.study="lightslategray",
             lty.fixed=2,plotwidth="5cm")
print(p2_1)
dev.off()


pdf('./p03-1.pdf', width = 9.5, height = 5.5)
p3_1<-forest(metainf(m3,pooled="random"),
             studlab = paste("Omitting:", data3$author,"(",data3$year,")","-" ,data3$Subgroup),
             family="sans",fontsize=9.5,
             lab.e="1-MCP",
             lab.c="Control",
             lwd=2,
             col.diamond.fixed="lightslategray",
             col.diamond.lines.fixed="lightslategray",
             col.diamond.random="maroon",
             col.diamond.lines.random="maroon",
             col.square="blue",
             col.study="lightslategray",
             lty.fixed=2,plotwidth="5cm")
print(p3_1)
dev.off()


m1
m2
m3

#-------------------subgroup-1---------------#
funnel(m1)

pdf('./p01-2.pdf', width = 7, height = 4)
p1_2<-funnel(m1, comb.fixed = TRUE, bg = data1$color,
             xlim = c(-3, 3), cex=2,
             ylim =c (0.25,-0)
             )+
  legend("bottomright",horiz=FALSE, inset=.05, title="Subgroup 1", 
         c("Ethylene production rate",
           "Respiration rate",
           "Disease incidence"),
         pch=19,pt.cex=1.2,cex=1,bty="o", 
       col=c("red", "yellow", "green"))
print(p1_2)
dev.off()




#-------------------subgroup-2---------------#
funnel(m2)

pdf('./p02-2.pdf', width = 7, height = 4)
p2_2<-funnel(m2, comb.fixed = TRUE, bg = data1$color,
             xlim = c(-7, 12), cex=2,
             ylim =c (0.7,-0)
)+
  legend("topright",horiz=FALSE, inset=.05, title="Subgroup 2", 
         c("APX activity",
           "POD activity",
           "SOD activity"),
         pch=19,pt.cex=1.2,cex=1,bty="o", 
         col=c("red", "yellow", "green"))
print(p2_2)
dev.off()



#-------------------subgroup-3---------------#
funnel(m3)

pdf('./p03-2.pdf', width = 7, height = 4)
funnel(m3, comb.fixed = TRUE, bg = data1$color,
             xlim = c(-13, 5), cex=2,
             ylim =c (0.9,-0)
)+
  legend("topright",horiz=FALSE, inset=.05, title="Subgroup 3", 
         c("Cellulose","Firmness",
           "Lignin","PAL activity",
           "CAD activity"),
         pch=19,pt.cex=1.2,cex=1,bty="o", 
         col=c("red", "yellow", "green", "blue", "grey"))
dev.off()

